// JavaScript Document

//===========Edit game===========================
function checkSubmit()
{

	if(document.getElementById('gamename').value == '' )
	{
		document.getElementById('gamename').focus();
		document.getElementById('gamename').style.backgroundColor = "#D45F55";
		return false;
	}
	if(document.getElementById('price').value == '' || isNaN(document.getElementById('price').value))
	{
		document.getElementById('price').focus();
		document.getElementById('gamename').style.backgroundColor = "#666666";
		document.getElementById('price').style.backgroundColor = "#D45F55";
		return false;
	}
	if( document.getElementById('size').value == '' || isNaN(document.getElementById('size').value))
	{
		document.getElementById('size').focus();
		document.getElementById('gamename').style.backgroundColor = "#666666";
		document.getElementById('price').style.backgroundColor = "#666666";
		document.getElementById('size').style.backgroundColor = "#D45F55";
		return false;
	}
		document.getElementById('gamename').style.backgroundColor = "#666666";
		document.getElementById('price').style.backgroundColor = "#666666";
		document.getElementById('size').style.backgroundColor = "#666666";
	return true;
}
function editGame(id,name,size,price,type,device,hot)
{
	showLoadingPage();
	document.getElementById('idGame').value = id;
	document.getElementById('gamename').value = name;
	document.getElementById('price').value = price;
	document.getElementById('size').value = size;
	document.getElementById('Hot').checked = Boolean(hot);
	document.getElementById('cbxType').value = parseInt(type);
	if(device==1)
	{
		document.getElementById('devIPhone').checked = true;
	}
	else
	{
		if(device == 3)
		{
			document.getElementById('devAll').checked = true;
		}
		else
		{		
			document.getElementById('devIPad').checked = true;
		}
	}
	loadEditer();
}

function loadEditer()
{
	$("#edit-box").fadeIn(1000);
		//
		
		
		// Add the mask1 to body
		$('body').append('<div id="mask2" onclick="javascript:exit();"></div>');
		$('#mask2').fadeIn(300);
	
	}
	function exit()
	{
		$('#mask2 , .edit-popup').fadeOut(300) ; 
		removeMask();
			$("#loadingpage").fadeOut(1000);
	}
	function removeMask(){$('#mask2').remove(); 
	} 
	
function createObject() 
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();

var nocache = 0;

function loadGameAdmin(page) 
{
	showLoadingPage();
	http.open('get', 'process/processListGameAmin.php?page='+page);
	http.onreadystatechange = loadGameAdminReply;
	http.send(null);

}
function loadGameAdminReply()
{
	if(http.readyState == 4){
	var response = http.responseText;
	// else if login is ok show a message: "Site added+ site URL".
	$("#tablegame").html(response);
	$("#loadingpage").fadeOut(1000);
	}
}
// search game admin
function searchGameAdmin(textSrc,type,page) 
{
	showLoadingPage();
	http.open('get', 'process/processListGameAmin.php?textSrc='+textSrc+'&type='+type+'&page='+page);
	http.onreadystatechange = searchGameAdminReply;
	http.send(null);

}
function searchGameAdminReply()
{
	if(http.readyState == 4){
	var response = http.responseText;
	// else if login is ok show a message: "Site added+ site URL".
	$("#tablegame").html(response);
	$("#loadingpage").fadeOut(1000);
	}
}
function deleteGame(id)
{
	if(confirm("Bạn có chắc xóa game "+id))
	{
		showLoadingPage();
		url = 'process/processDeleteGame.php?id='+id;
		http.open('get', url);
		http.onreadystatechange = deleteGameAdminReply;
		http.send(null);
		//window.location = "process/processDeleteGame.php?id="+id;
	}
	else
	{
		return false;
	}
}
function deleteGameAdminReply()
{
	if(http.readyState == 4){
	var response = http.responseText;
	// else if login is ok show a message: "Site added+ site URL".
	$("#request").html(response);
	$("#loadingpage").fadeOut(1000);
	}
}
// upload banner
